var rAF = (function () {
  return (
    window.requestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      function (callback) {
        window.setTimeout(callback, 1000 / 60)
      }
  )
}())

var frame = 0
var lastTime = Date.now()
var fps_ = 30 // 上一个fps
var fps__ = 30 // 上上个fps

var loop = function () {
  var now = Date.now()

  frame++

  if (now > 1000 + lastTime) {
    var fps = Math.round((frame * 1000) / (now - lastTime))

    window.dynamicChangeMSSE(fps < 30 && fps_ < 30 && fps__ < 30) // 修改maximumScreenSpaceError

    fps__ = fps_
    fps_ = fps
    frame = 0
    lastTime = now
  };

  rAF(loop)
}

module.exports = {
  loop
}
